﻿using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;

namespace WgpgGUI
{
    public partial class PassphraseStrength : UserControl
    {
        private PasswordStrengths m_strength;

        public static readonly DependencyProperty StrengthColorProperty =
            DependencyProperty.Register("StrengthColor", typeof(Brush),
            typeof(PassphraseStrength), new UIPropertyMetadata(new SolidColorBrush(Colors.Transparent)));

        public PassphraseStrength()
        {
            InitializeComponent();
            mainGrid.DataContext = this;
            Strength = PasswordStrengths.None;
        }

        public PasswordStrengths Strength
        {
            get { return m_strength; }
            set
            {
                if (m_strength == value)
                    return;

                m_strength = value;

                textblock_weak.Text = String.Empty;
                textblock_medium.Text = String.Empty;
                textblock_strong.Text = String.Empty;
                textblock_best.Text = String.Empty;

                switch (m_strength)
                {
                    case PasswordStrengths.Weak:
                        textblock_weak.Text = L10N.T("strength_weak");
                        StrengthColor = new SolidColorBrush(Colors.Red);
                        break;
                    case PasswordStrengths.Medium:
                        textblock_medium.Text = L10N.T("strength_medium");
                        StrengthColor = new SolidColorBrush(Colors.Orange);
                        break;
                    case PasswordStrengths.Strong:
                        textblock_strong.Text = L10N.T("strength_strong");
                        StrengthColor = new SolidColorBrush(Colors.LightGreen);
                        break;
                    case PasswordStrengths.Best:
                        textblock_best.Text = L10N.T("strength_best");
                        StrengthColor = new SolidColorBrush(Colors.Green);
                        break;
                    default:
                        StrengthColor = new SolidColorBrush(Colors.Transparent);
                        break;
                }
            }
        }

        protected Brush StrengthColor
        {
            get { return (Brush)GetValue(StrengthColorProperty); }
            set { SetValue(StrengthColorProperty, value); }
        }
    }

    public enum PasswordStrengths
    {
        None = 0,
        Weak = 1,
        Medium = 2,
        Strong = 3,
        Best = 4
    }
}
